<?php

namespace app\mobile\controller;

use think\Controller;
use think\Request;

class base extends Controller
{
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        echo '我是手机版';

        //全站信息
        $system = model('system')->getnoteall('system');

        //头部导航
        $navs = model('nav')->catenav();

        //底部头部
        $nav = model('nav')->where('pid', '0')->order('sort ASC,id ASC')->limit(10)->select();

        //在线帮助
        $online = model('online')->select();

        //幻灯片
        $where = '';
        $navid = $this->request->param('navid');
        !empty($navid) ? $where['type'] = ['like', '%,' . $navid . ',%'] : '';
        $carousel = model('carousel')->where($where)->select();
        //友情链接
        $link = model('link')->limit(6)->select();

        $this->assign([
            'carousel' => $carousel,
            'online' => $online,
            'link' => $link,
            'navs' => $navs,
            'nav' => $nav,
            'system' => $system,
        ]);
    }


    protected $beforeActionList = [
        'right' =>  ['only'=>'index,detailed'],
    ];

    public function index()
    {
        $model = $this->request->controller();
        $where = '';
        $cid = $this->request->param('navid');
        !empty($cid) ? $where['cid'] = $cid : '';
        $list = model($model)->where($where)->order('sort ASC,create_time DESC,id DESC')->paginate();
//        echo model($model)->getLastSql();
        $this->assign('list', $list);
        return $this->fetch();
    }


    public function detailed($id)
    {
        //显示内容
        $model = $this->request->controller();
        $data = model($model)->find($id);

        //更多页面
        !empty($data['cid']) ? $datas['cid'] = $data['cid'] : '';
        $next = model($model)->getnext($id, $datas);

        $this->assign('data', $data);
        $this->assign('next', $next);
        return $this->fetch();
    }

    //左边导航
    public function right()
    {

        $pid = model('nav')->where('id',$this->request->param('navid'))->value('pid');
        $pid = !empty($pid)?$pid:$this->request->param('navid');
        $reight_nav = model('nav')
            ->where('pids', 'like', '%,' . $pid . ',%')
            ->order('sort asc,id ASC')
            ->select();

        $this->assign('reight_nav', $reight_nav);

    }


}
